package com.fanben100.gui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.KeyStroke;

import com.fanben100.gui.i18n.ResourceContext;

/**
 * 开卡窗口
 * 
 * @author Administrator
 * 
 */
public class OpenCardDialog extends JDialog {

	/**
	 * 
	 */
	private ResourceContext rt = ResourceContext.getInstance("OpenCardDialog");

	private static final long serialVersionUID = 1L;

	private JLabel cardNoLabel = new JLabel(rt.getColonString("cardNo"),
			JLabel.LEFT);
	private JTextField cardNoField = new JTextField("", 20);

	private JLabel identityNoLable = new JLabel(
			rt.getColonString("identityNo"), JLabel.LEFT);
	private JTextField identityNoField = new JTextField("", 20);

	private JLabel cardPasswordLabel = new JLabel(
			rt.getColonString("cardPassword"), JLabel.LEFT);
	private JPasswordField cardPasswordField = new JPasswordField(15);

	private JLabel cardRepeatPasswordLabel = new JLabel(
			rt.getColonString("cardRepeatPassword"), JLabel.LEFT);
	private JPasswordField cardRepeatPasswordField = new JPasswordField(15);

	private JButton registButton = new JButton(rt.getString("registButton"));

	public OpenCardDialog(JFrame frame, String title, boolean modal) {
		super(frame, title, modal);
		this.setSize(new Dimension(180, 100));
		this.setLocationRelativeTo(frame);
		this.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				dispose();
			}
		});
		try {
			jbInit();
			pack();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	private void jbInit() throws Exception {
		this.setResizable(false);
		JPanel sellerRegistPanel = new JPanel(false);
		sellerRegistPanel.setLayout(new BoxLayout(sellerRegistPanel,
				BoxLayout.X_AXIS));
		registButton.setSize(new Dimension(20, 10));
		registButton.addActionListener(new SellerRegistAction());
		registButton.registerKeyboardAction(new SellerRegistAction(),
				KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
				JComponent.WHEN_IN_FOCUSED_WINDOW);

		cardPasswordField.setEchoChar('*');
		cardRepeatPasswordField.setEchoChar('*');
		JPanel labelPanel = new JPanel(false);
		labelPanel.setLayout(new GridLayout(0, 1));
		labelPanel.add(cardNoLabel);
		labelPanel.add(identityNoLable);
		labelPanel.add(cardPasswordLabel);
		labelPanel.add(cardRepeatPasswordLabel);

		JPanel fieldPanel = new JPanel(false);
		fieldPanel.setLayout(new GridLayout(0, 1));
		fieldPanel.add(cardNoField);
		fieldPanel.add(identityNoField);
		fieldPanel.add(cardPasswordField);
		fieldPanel.add(cardRepeatPasswordField);

		getContentPane().setLayout(new BorderLayout());

		sellerRegistPanel.add(labelPanel);
		sellerRegistPanel.add(fieldPanel);
		this.getContentPane().add(sellerRegistPanel, BorderLayout.CENTER);
		this.getContentPane().add(registButton, BorderLayout.PAGE_END);
		getContentPane().setSize(new Dimension(500, 400));
	}

	/**
	 * 会员注册Action
	 * 
	 * @author Administrator
	 * 
	 */
	private void submitCardRegist() {

	}

	private class SellerRegistAction implements ActionListener {

		public void actionPerformed(ActionEvent e) {

		}

	}
}
